package com.dylan.历史.算法;

/**
 * @author : ankang
 * @date : 2019/10/17 20:58
 * @Description : 在数组中查找小于等于指定值的最大值
 */
public class 基础_查找_二分查找_LE {

    public static void main(String[] args) {
        System.out.println(searchLe(new int[]{1, 2}, 0, 1, 0));
    }

    private static int searchLe(int[] nums, int l, int r, int val) {
        while (l <= r) {
            int m = (l + r) / 2;
            if (nums[m] <= val) {
                if (m == r || nums[m + 1] > val) {
                    return m;
                } else {
                    l = m + 1;
                }
            } else {
                r = m - 1;
            }
        }
        return -1;
    }
}
